//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "NullCalendar.h"
using namespace Cephei::QL::Times::Calendars;
#include <gen/QL/Times/Period.h>
#include <gen/QL/Times/Calendar.h>
using namespace Cephei::QL::Times;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Times::Calendars::CNullCalendar::CNullCalendar () : CCalendar(CNullCalendar::typeid)
{
    try
    {
#ifdef HANDLE
        _phNullCalendar = NULL;
#endif
        _ppNullCalendar = new boost::shared_ptr<QuantLib::NullCalendar> (new QuantLib::NullCalendar ( ));
        SetCalendar (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppNullCalendar));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::Calendars::CNullCalendar::CNullCalendar (boost::shared_ptr<QuantLib::NullCalendar>& childNative, Object^ owner) : CCalendar(CNullCalendar::typeid)
{
#ifdef HANDLE
	_phNullCalendar = NULL;
#endif
	_ppNullCalendar = &childNative;
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppNullCalendar));
}
Cephei::QL::Times::Calendars::CNullCalendar::CNullCalendar (QuantLib::NullCalendar& childNative, Object^ owner) : CCalendar(CNullCalendar::typeid)
{
#ifdef HANDLE
	_phNullCalendar = NULL;
#endif
	_ppNullCalendar = new boost::shared_ptr<QuantLib::NullCalendar> (&childNative);
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppNullCalendar));
    _NullCalendarOwner = owner;
    _CalendarOwner = owner;
}

Cephei::QL::Times::Calendars::CNullCalendar::CNullCalendar (CNullCalendar^ copy) : CCalendar(CNullCalendar::typeid)
{
#ifdef HANDLE
	_phNullCalendar = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppNullCalendar = new boost::shared_ptr<QuantLib::NullCalendar> (copy->GetShared());
        _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppNullCalendar));
    }
}
Cephei::QL::Times::Calendars::CNullCalendar::CNullCalendar (System::Type^ t) : CCalendar(CNullCalendar::typeid)
{
#ifdef HANDLE
	_phNullCalendar = NULL;
#endif
	if (!t->IsSubclassOf(CNullCalendar::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Times::Calendars::CNullCalendar::CNullCalendar (QuantLib::Handle<QuantLib::NullCalendar>& childNative, Object^ owner)  : CCalendar(CNullCalendar::typeid)
{
	_phNullCalendar = &childNative;
	_ppNullCalendar = &static_cast<boost::shared_ptr<QuantLib::NullCalendar>>(childNative.currentLink());
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppNullCalendar));
    _NullCalendarOwner = owner;
}
Cephei::QL::Times::Calendars::CNullCalendar::CNullCalendar (QuantLib::Handle<QuantLib::NullCalendar> childNative)  : CCalendar(CNullCalendar::typeid)
{
	_phNullCalendar = &childNative;
	_ppNullCalendar = &static_cast<boost::shared_ptr<QuantLib::NullCalendar>>(childNative.currentLink());
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppNullCalendar));
}
#endif
#ifdef STRUCT
Cephei::QL::Times::Calendars::CNullCalendar::CNullCalendar (QuantLib::NullCalendar childNative)  : CCalendar(CNullCalendar::typeid)
{
#ifdef HANDLE
	_phNullCalendar = NULL;
#endif
	_ppNullCalendar = new boost::shared_ptr<QuantLib::NullCalendar> (new QuantLib::NullCalendar (childNative));
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppNullCalendar));
}
#endif

Cephei::QL::Times::Calendars::CNullCalendar::~CNullCalendar ()
{
    if (_ppNullCalendar != NULL)
    {
	    delete _ppNullCalendar;
        _ppNullCalendar = NULL;
    }
}
Cephei::QL::Times::Calendars::CNullCalendar::!CNullCalendar ()
{
    if (_ppNullCalendar != NULL)
    {
	    delete _ppNullCalendar;
    }
}
QuantLib::NullCalendar& Cephei::QL::Times::Calendars::CNullCalendar::GetReference ()
{
    if (_ppNullCalendar == NULL) throw gcnew NativeNullException ();
	return **_ppNullCalendar;
}
boost::shared_ptr<QuantLib::NullCalendar>& Cephei::QL::Times::Calendars::CNullCalendar::GetShared ()
{
    if (_ppNullCalendar == NULL) throw gcnew NativeNullException ();
	return *_ppNullCalendar;
}
QuantLib::NullCalendar* Cephei::QL::Times::Calendars::CNullCalendar::GetPointer ()
{
    if (_ppNullCalendar == NULL) throw gcnew NativeNullException ();
	return &**_ppNullCalendar;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::NullCalendar>& Cephei::QL::Times::Calendars::CNullCalendar::GetHandle ()
{
	if (_phNullCalendar == NULL)
	{
		_phNullCalendar = new Handle<QuantLib::NullCalendar> (*_ppNullCalendar);
	}
	return *_phNullCalendar;
}
#endif
bool Cephei::QL::Times::Calendars::CNullCalendar::HasNative () 
{
	return (_ppNullCalendar != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Times::Calendars::INullCalendar^ Cephei::QL::Times::Calendars::CNullCalendar_Factory::Create ()
{
    return gcnew CNullCalendar ();
}
